-- Function: sp_eliminar_cliente(character varying)

-- DROP FUNCTION sp_eliminar_cliente(character varying);

CREATE OR REPLACE FUNCTION sp_delete_cliente(cedula character varying)
  RETURNS void AS
$BODY$ 
begin
    delete from public."Clientes"
    where "txtCI" = CEDULA;
end;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION sp_eliminar_cliente(character varying)
  OWNER TO postgres;

--PROVEEDOR
CREATE OR REPLACE FUNCTION sp_delete_proveedor(empresa character varying)
  RETURNS void AS
$BODY$ 
begin
    delete from public."Proveedores"
    where "txtNomEmpresa" = EMPRESA;
end;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION sp_delete_proveedor(character varying)
  OWNER TO postgres;

--EMPLEADO
CREATE OR REPLACE FUNCTION sp_delete_empleado(ci character varying)
  RETURNS void AS
$BODY$ BEGIN
DELETE FROM public."Empleados" WHERE "txtCIEmpleado" = CI;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION sp_delete_empleado(character varying)
  OWNER TO postgres;

--EMPLEADO USERS
CREATE OR REPLACE FUNCTION sp_delete_empleado_users(ci character varying)
  RETURNS void AS
$BODY$ BEGIN
DELETE FROM public."EMPLEADOS_USERS" WHERE "numIDEmpleado" = 
(select "numIDEmpleado" from public."Empleados" where "txtCIEmpleado" = CI);
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION sp_delete_empleado_users(character varying)
  OWNER TO postgres;
 
 --CATEGORIAS
 CREATE OR REPLACE FUNCTION sp_delete_categorias(descripcion character varying)
  RETURNS void AS
$BODY$ BEGIN
DELETE FROM public."Categorias" WHERE "txtNombreCategoria" = descripcion;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE;
  --PRODUCTO
 CREATE OR REPLACE FUNCTION sp_delete_producto(codigo int)
  RETURNS void AS
$BODY$ BEGIN
DELETE FROM public."Productos" WHERE "numIDProducto" = $1;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE;
--PRODUCTO_INVENTARIO
 CREATE OR REPLACE FUNCTION sp_delete_producto_inventario(codigo int)
  RETURNS void AS
$BODY$ BEGIN
DELETE FROM public."PRODUCTO_INVENTARIO" WHERE "numIDProducto" = $1;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE;  
  --PRODUCTO_PROVEEDOR
   CREATE OR REPLACE FUNCTION sp_delete_producto_proveedor(codigo int)
  RETURNS void AS
$BODY$ BEGIN
DELETE FROM public."PRODUCTO_PROVEEDOR" WHERE "numIDProducto" = $1;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE;